package cn.memset.code.functionInterface;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.function.Supplier;

public class SupplierExample {
    public static void main(String[] args) {
        testSupplierWithLambda();
    }

    public static void testSupplierWithLambda() {
        final Random random = new Random();

        lazyPrint(() -> {
            return random.nextInt(100);
        });

        lazyPrint(() -> {
            try {
                System.out.println("waiting for 3s...");
                Thread.sleep(3*1000);
            } catch (InterruptedException e) {
                // do nothing
            }

            return random.nextInt(100);
        });
    }

    public static void lazyPrint(Supplier<Integer> lazyValue) {
        System.out.println(lazyValue.get());
    }
}
